<template>
  <div class="dataset">
    <!-- 按钮 -->   
    <div class="btns">
      <el-form size="small" inline style="text-align:right">
        <br>
        <el-form-item label="名称">
          <el-input v-model="param.name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" plain @click="loadDataset">搜索</el-button>
          <el-button type="primary" size="small" @click="toAddHandler" plain><i class="el-icon-edit"> 新增训练</i></el-button>
        </el-form-item>
      </el-form>
        <div style="text-align:right">
        <el-button size= "small" type="warning" round  @click="downloadHandler">导出</el-button>
        </div>
    </div>
    <!-- /按钮 -->
    <!-- {{datasets}}  -->
    <!-- 表格 -->
    <el-table :data="dataset" border="ture" >
      <el-table-column type="index" :index="1" label="序号" align="center" width="100"></el-table-column>
      <el-table-column label="名称" prop="name" align="center" width="250"></el-table-column>
      <el-table-column label="介绍" prop="introduce" align="center"></el-table-column>
      <el-table-column label="图片" prop="photo" align="center" width="140px">
        <template slot-scope="scope">
          <div style="width:120px;border-radius:5px;height:100px;over-flow:hidden" >
            <img :src="scope.row.photo" alt="" style="width:100%">
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="176" align="center">
        <!-- 定制-插槽 -->
        <template slot-scope="scope">
          <el-button type="primary" plain size="mini" icon="el-icon-edit" @click="updateHandler(scope.row)">修改</el-button>
          <br>
          <br>
          <el-button type="danger" plain size="mini" icon="el-icon-delete" @click="deleteHandler(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- /定制-插槽 -->
    <!-- /表格 -->
    <!-- 模态框 -->
    <!-- /模态框 -->
  </div>
</template>
<script>
import {del, get } from "@/utils/request";
export default {
  //页面数据
  data() {
    return {
      //参数，用于保存检索的参数
      param: {},
      //组件模板中需要的数据
      dataset: []
    };
  },
  //页面渲染的时候会调用的函数
  created() {
    this.loadDataset();
  },
  //所有的方法
  methods: {
    //导出
     downloadHandler(){
      window.location.href = "http://8.131.68.179:9999/dataset/download?name="+this.param.name
    },
    //修改事件处理函数
    updateHandler(row){
       //跳转到修改页面（新增页面）
       //跳转携带当前行的数据
       this.$router.push({
           path:"/dataset/create",     //跳转的路径（前端）
           query:row    //携带的参数
       })
    },
    //删除事件处理函数
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let url = "http://8.131.68.179:9999/dataset/deleteByID";
        del(url, { id: row.id }).then(resp => {
          this.$message({ type: "success", message: resp.message });
          this.loadDataset();
        });
      });
    },
    //跳转
    toAddHandler() {
      this.$router.push("/dataset/create");
    },
    //查询后台中的应用信息
    loadDataset() {
      let url = "http://8.131.68.179:9999/dataset/query";
      get(url, this.param).then(resp => {
        this.dataset = resp.data;
      });
    }
  }
};
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
}
  .el-form {
    background:#0db66f;
  }
</style>